package com.thread;

public class ThreadExit {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
//        t.start();
        new Thread(t).start();

        Thread.sleep(20*100);
        t.setLoop(false);
    }
}

class T implements Runnable{
    private int count = 20;
    private boolean loop = true;
    @Override
    public void run() {
        while (loop){
            if (count>100){
                System.out.println("结束");
                return;
            }
            try {
                Thread.sleep(50);
                System.out.println(count);
            }catch(InterruptedException e){
                e.printStackTrace();
            }
            count++;

        }
    }
    public void setLoop(boolean loop){
        this.loop = loop;
    }
}
